package com.santiao.publics.ad.ads;

import android.os.Bundle;
import android.os.Message;
import android.util.Log;

import com.santiao.publics.callback.OnResponseListener;
import com.santiao.publics.config.Const;
import com.santiao.publics.util.HttpUtilSS;
import com.santiao.publics.util.SharedPreferencesUtil;

import java.util.HashMap;
import java.util.Map;

public           class AdRequestService {

    private Map<String,String> reportMap ;
    private static String   appId;
    private static String   djId;
    public  void  initAdRequest(String actionType,String adStyle, String ecpm,String placementId ,String slotId,String adPlatForm){
        appId = SharedPreferencesUtil.getString("appId");
        djId  = SharedPreferencesUtil.getString("djId");
        if(adPlatForm==null || adPlatForm=="") {
            adPlatForm = "csj";
        }
        reportMap = new HashMap<>();
        reportMap.put("actionType",actionType);//	行为类型, 0:展示、1:点击	2广告请求	true
        reportMap.put("adStyle",adStyle);//	广告样式, 0:信息流、1:全屏、2:插屏、3:激励视频、4:开屏、5:banner广告		true
        reportMap.put("djId",djId);//	djId		true
        reportMap.put("appId",appId);//	APP唯一标识		true


        reportMap.put("adPlatForm",adPlatForm);//	广告平台(可为空字符串、不能为空)、例：ks、oppo、csj(穿山甲)、bqt(百度)		true

        reportMap.put("ecpm",ecpm);//	ecpm, 收益(单位:分)		true
        reportMap.put("adId",slotId);//	代码位ID		false
        reportMap.put("placementId",placementId);//	广告位ID		false
        reportMap.put("scene","iapp");//		应用内=iapp ; 应用外=oapp
    }


    public  void reportRequest(){
        new Thread(runnable).start();
    }

//    Handler handler = new Handler(){
////        @Override
//        public void handleMessage(Message msg) {
//            super.handleMessage(msg);
//            Bundle data = msg.getData();
//            String val = data.getString("value");
//            Log.i(Const.TAG,"请求结果:" + val);
//        }
//    };

    Runnable runnable = new Runnable(){
        @Override
        public void run() {
            // TODO: http request.
            Message msg = new Message();
            Bundle data = new Bundle();
            data.putString("value","请求结果");



            String url = Const.URL_Q+"/dj-tools-api/app/v2/report";
            HttpUtilSS.getRequest(url, reportMap, new OnResponseListener() {
                @Override
                public void onSuccess(String response) {
                    Log.d(Const.TAG, url + "---ok-------:" + reportMap.toString() + "----------:" + response);

                }

                @Override
                public void onError(String responseBody,String error) {
                    Log.d(Const.TAG, url + "---err-------:" + reportMap.toString() + "----------:" +responseBody+"----------:"+ error);

                }
            });
            msg.setData(data);
//            handler.sendMessage(msg);
        }
    };

}
